package com.restaurant.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 
 * @author TRz
 * @date 2020年8月4日上午9:43:30
 * @remarks TODO
 */
public class JDBCUtils {

	public static Connection getConnection() {
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			//我本地的数据库
			//conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ghostorder", "root", "879");
			conn = DriverManager.getConnection("jdbc:mysql://111.230.205.165:3306/U0Order?characterEncoding=utf-8", "U0Order", "JavaGhost");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	
	public static void close(ResultSet rs, Statement stmt, PreparedStatement pstmt, Connection conn) {
		try {
			if (null != rs) {
				rs.close();
			}
		} catch (Exception e) {
		}
		try {
			if (null != stmt) {
				stmt.close();
			}
		} catch (Exception e) {
		}
		try {
			if (null != pstmt) {
				pstmt.close();
			}
		} catch (Exception e) {
		}
		try {
			if (null != conn) {
				conn.close();
			}
		} catch (Exception e) {
		}
	}
}
